using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


//namespace Herenity
//{

    /// <summary>
    /// 按键输入管理器。
    /// </summary>
    public class InputKeysManager : SingletonPatternBase<InputKeysManager>
    {
        //是否启用本脚本的功能，监听玩家按键输入。
        /// <summary>
        /// false时不可移动
        /// </summary>
        public bool Move_Lock { get; private set; }
        /// <summary>
        /// false时不可旋转
        /// </summary>
        public bool Rot_Lock { get; private set; }

        /// <summary>
        /// 是否激活按键监听
        /// 传入true，会激活按键监听，这样玩家通过按键输入管理器输入的操作才会生效。
        /// 传入false，会禁用按键监听，这样玩家通过按键输入管理器输入的操作就会无效。
        /// </summary>
        /// <param name="move">移动</param>
        /// <param name="rot">旋转</param>
        public void Active(bool move = true, bool rot = true)
        {
            Move_Lock = move;
            Rot_Lock = rot;
            Debug.Log("当前是否可以移动：" + move);
            Debug.Log("当前是否可以旋转：" + rot);
        }

        public void Unactive()
        {
            Move_Lock = false;
            Rot_Lock = false;
            Debug.Log("当前不可移动、不可旋转");
        }

        public InputKeysManager()
        {
            MonoManager.Instance.AddUpdateListener(CheckKeys);
        }

        void CheckKeys()
        {
            if (!Move_Lock) return;

            foreach (var item in Enum.GetValues(typeof(KeyCode)))
            {
                CheckKeysCode((KeyCode)item);
            }

            for (int i = 0; i <= 2; i++)
            {
                if (Input.GetMouseButtonDown(i))
                {
                EventCenterManager.Broadcast(E_InputCommand.GetMouseButtonDown, i);
                }
                if (Input.GetMouseButtonUp(i))
                {
                EventCenterManager.Broadcast(E_InputCommand.GetMouseButtonUp, i);
                }
                if (Input.GetMouseButton(i))
                {
                EventCenterManager.Broadcast(E_InputCommand.GetMouseButton, i);
                }
            }
        }

        void CheckKeysCode(KeyCode key)
        {
            if (Input.GetKeyDown(key))
            {
                EventCenterManager.Broadcast(E_InputCommand.GetKeyDown, key);
            }
            if (Input.GetKeyUp(key))
            {
                EventCenterManager.Broadcast(E_InputCommand.GetKeyUp, key);
            }
            if (Input.GetKey(key))
            {
                EventCenterManager.Broadcast(E_InputCommand.GetKey, key);
            }
        }
    }
